const state = () => ({
  course: [],
  trainingCamp: ""
});

const mutations = {
  getClinic(state, { trainingCamp, result }) {
    state.course = state.course.concat(result);
    state.trainingCamp = trainingCamp;
  }
};

const actions = {
  async getClinic({ commit }, { count = 3, page = 1 }) {
    return new Promise(resolve => {
      fetch("http://118.31.35.160:4000/course", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${localStorage.getItem("token")}`
        },
        body: JSON.stringify({
          count,
          page
        })
      })
        .then(res => res.json())
        .then(res => {
          commit("getClinic", res);
          resolve(res.result.length);
        });
    });
  }
};

export default {
  state,
  mutations,
  actions
};
